package com.peanuts.tender.controller;

import com.peanuts.tender.bean.Result;
import com.peanuts.tender.service.TestService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping(value = "/tender")
public class TenderController extends BaseController{
    Logger log = Logger.getLogger(TenderController.class);
    @Autowired
    private TestService testServiceImpl;
    @RequestMapping(value = "/list/{pageIndex}")
    public Result list(@PathVariable("pageIndex") Integer pageIndex) {
        String type = getRequest().getParameter("type");

        System.out.println(pageIndex);
        System.out.println(type);
        Result result = new Result();
        try {
            result.setCode(1).setContent(testServiceImpl.tenderList(type,pageIndex));
        }catch (Exception e){
            log.error("查询列表异常"+e);
            result.setCode(-1).setMsg("查询列表异常");
        }
        return result;
    }

    @RequestMapping(value = "/search/{pageIndex}")
    public Result search(@PathVariable("pageIndex") Integer pageIndex) {
        String keyword = getRequest().getParameter("keyword");

        System.out.println(pageIndex);
        System.out.println(keyword);
        Result result = new Result();
        try {
            result.setCode(1).setContent(testServiceImpl.keywordSearch(keyword,pageIndex));
        }catch (Exception e){
            log.error("查询列表异常"+e);
            result.setCode(-1).setMsg("查询列表异常");
        }
        return result;
    }

}